<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="java.util.*" %>
<%@ page import="org.goldfish.cookied_chatroom02.entity.PreviewBean" %>

<html>
<head>
    <title>欢迎，${sessionScope.get("name")}</title>
</head>
<body>
<div id="message_display_div">
    <label>留言</label>
    <br/>
    <table>
        <tr>
            <td>发送方</td>
            <td>标题</td>
            <td>摘要</td>
        </tr>

        <c:forEach var="preview" items="${requestScope.previews}"
                   varStatus="status">
            <tr>
                <td>${preview.sender}</td>
                <td>${preview.title}</td>
                <td>${preview.summary}</td>
            </tr>
            <form method="get"
                  action="chat">
                <fieldset>
                    <button type="submit" name="message_id_for_detail" value="${preview.id}">查看详情</button>
                </fieldset>
            </form>
        </c:forEach>
    </table>
</div>
<div id="message_send_div">
    <label>发送留言</label>
    <form action="chat" method="post" id="chat_form">
        <fieldset>
            <br/>
            <label for="title_field">标题
                <input id="title_field" type="text" name="title_input" value="无标题">
            </label>
            <br/>
            <label for="message_field">信息内容<br/>
                <textarea id="message_field" name="message_input" rows="5" cols="40"></textarea>
            </label>
            <br/>
            <label for="receiver_select">选择收件人
                <select name="selected_receiver" id="receiver_select">
                    <c:forEach
                            var="receiver_candidate"
                            items="${requestScope.receivers_to_display}">
                        <option value="${receiver_candidate}">${receiver_candidate}</option>
                    </c:forEach>
                </select>
            </label>
            <button type="submit" name="submit_type" value="send">发送</button>
        </fieldset>

    </form>
</div>
<label>用户ID: ${sessionScope.get("user_id")}</label>

</body>
<script type="application/javascript">
    <c:set var="message" >
    ${requestScope.get("error_message")}
    </c:set>
    <c:choose>
    <c:when test="${message == null}"/>
    <c:when test="${message == \"\"}"/>
    <c:otherwise>
    alert("${message}")
    </c:otherwise>
    </c:choose>
</script>
</html>
